<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Event bubbling</title>
    <style>
        .child {
            background-color: aliceblue;
            border: 2px solid black;
            padding: 14px;
            margin: 14px;
            cursor: pointer;
        }

        .childContainer {
            background-color: beige;
            padding: 14px;
            margin: 14px;
        }

        .container {
            background-color: rgb(227, 227, 28);
            padding: 14px;
            margin: 14px;
        }
    </style>
</head>

<body>
    <div class="container">
        <section class="childContainer">
            <div class="child">
                I am a child
            </div>
        </section>
    </div>
    <script>
        document.querySelector(".child").addEventListener("click", (e) => {
            e.stopPropagation()
            alert("Child Was clicked")
        })

        document.querySelector(".childContainer").addEventListener("click", (e) => {
            e.stopPropagation()
            alert("childContainer Was clicked")
        })

        document.querySelector(".container").addEventListener("click", (e) => {
            alert("container Was clicked")
        })

        function getRandomColor() {
            let val1 = Math.ceil(0 + Math.random() * 255);
            let val2 = Math.ceil(0 + Math.random() * 255);
            let val3 = Math.ceil(0 + Math.random() * 255);
            return `rgb(${val1}, ${val2}, ${val3})`
        }
        // let a = setInterval(() => {
        //     document.querySelector(".childContainer").style.background = getRandomColor();
        // }, 1000);

        // console.log(a)

        let a = setTimeout(() => {
            document.querySelector(".childContainer").style.background = getRandomColor();
        }, 5000);

        console.log(a)


    </script>
</body>

</html>